import os
import xlrd


def execCmd(cmd):
    r = os.popen(cmd)
    text = r.read()
    r.close()
    return text


def read(path):
    # 打开 xls 文件
    if os.path.exists(path):
        print('文件存在')
        book = xlrd.open_workbook(path)
        print("表单数量:", book.nsheets)
        print("表单名称:", book.sheet_names())
        # 获取第 1 个表单
        app = {}
        for sheet in book.sheet_names():
            sh = book.sheet_by_name(sheet)
            for i in range(1, sh.nrows):
                if not sh.cell_value(i, 1):
                    continue
                index = sh.row_values(i)  # 某一行数据
                app[index[0]] = index[1]
        return app
    else:
        print('文件不存在')
        return None


if __name__ == '__main__':
    path = input('请输入要读取的Excel路径:')
    ipList = read(path)
    print("Length : %d" % len(ipList))
    if ipList:

        while True:
            data = input('请输入编号:')
            if data in ipList:
                print("编号对应的IP", ipList[data])
            else:
                print("未找到对应编号")
